<template>
	<view>
		<view class="notice" @click="show1=true" v-if="!addrtoken">
			<image src="/static/notice.png" class="notice__icon" mode=""></image>
			<view class="notice__text">
				请先登录后查看商品详情
			</view>
			<image src="/static/close.png" class="notice__close" mode=""></image>
		</view>
		<view class="notice" @click="show1=true" v-else>
			<image src="/static/notice.png" class="notice__icon" mode=""></image>
			<view class="notice__text">
				重新登录
			</view>
			<image src="/static/close.png" class="notice__close" mode=""></image>
		</view>
		<view class="head">
			<view class="head__title">
				商品标题
			</view>
			<view class="head__price">
				价格
			</view>
			<view class="head__kc">
				库存
			</view>
			<view class="head__cz">
				操作
			</view>
		</view>
		<view class="list">
			<view class="list__item" v-for="(item,index) in list" :key="index">
				<view class="list__item__title">
					<image @click="clickpre(item.image)" :src="'http://dan.fuliaoxx.com'+item.image"
						class="list__item__title__pic" mode="aspectFill"></image>
					{{item.name}}
				</view>
				<view class="list__item__price">
					{{item.price}}
				</view>
				<view class="list__item__price">
					{{item.num>0?'有':'无'}}
				</view>
				<view class="list__item__cz" @click="clicklq(item)">
					领取
				</view>
			</view>
		</view>
		<view class="footer">
			<view class="footer__btn" @click="to('/pages/index/hsaddr')">
				下不了回收地址
			</view>
			<!-- <view class="footer__btn btn1" @click="show=true">
				回收单号带地址结账
			</view> -->
		</view>
		<u-popup :show="show" bgColor='transparent' mode='center'>
			<view class="popbox">
				<view class="popbox__text">
					回收成功请截图移步私人微信结账
				</view>
				<u-button text="确认" @click="show=false,to('/pages/index/addr')" color="#3262FD" :customStyle="{width:'261rpx'}"
					shape='circle'></u-button>
			</view>
		</u-popup>
		<u-popup :show="show1" mode='center' round="30rpx" @close="show1=false">
			<view class="popbox1">
				<view class="popbox__text" style="margin: 0;padding: 0;">
					登录
				</view>
				<view class="dd">
					<view class="dd__label">
						手机号
					</view>
					<input type="number" maxlength="11" v-model="phone" class="dd__inp" placeholder="请输入手机号" />
				
				</view>
				<u-button text="确认" @click="clicklogin" color="#3262FD" :customStyle="{width:'261rpx',marginTop:'30rpx'}"
					shape='circle'></u-button>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import {
		getGoods,
		give,
		mobilelogin
	} from '@/api/home.js'
	export default {
		data() {
			return {
				show: false,
				list: [],
				show1:false,
				phone:'',
				addrtoken:uni.getStorageSync('addrtoken')
			};
		},
		methods: {
			to(url) {
				uni.navigateTo({
					url
				})
			},
			open() {
				// 通过组件定义的ref调用uni-popup方法 ,如果传入参数 ，type 属性将失效 ，仅支持 ['top','left','bottom','right','center']
				this.$refs.popup.open('top')
			},
			getlist() {
				getGoods().then(res => {
					if (res.data.code == 1) {
						this.list = res.data.data
					}
				})
			},
			clicklq(item) {
				uni.showLoading({
					title: '正在领取'
				})
				give({
					id: item.id
				}).then(res => {
					if (res.data.code == 1) {
						uni.showToast({
							title: '领取成功',

						})
						setTimeout(() => {
							uni.hideLoading()
							uni.navigateTo({
								url: '/pages/index/lq?addr=' + item.address + '&code=' + item
									.code + '&username=' + item.username + '&phone=' + item.phone +
									'&id=' + item.id
							})
						}, 1000)
					}
				})
				// to('/pages/index/lq')
			},
			clickpre(url) {
				uni.previewImage({
					urls: ['http://dan.fuliaoxx.com'+url],
					current:0
				});
			},
			clicklogin(){
				if(!this.phone){
					uni.$u.toast('请输入手机号')
					return
				}
				mobilelogin({phone:this.phone}).then(res=>{
					
					if(res.data.code==1){
						uni.setStorageSync('addrtoken',res.data.data.userinfo.token)
						uni.$u.toast('登录成功')
						this.phone=''
						this.show1=false
					}
				})
			}
		},
		onShow() {
			this.getlist()
		}
	}
</script>

<style lang="scss">
	.notice {
		height: 97rpx;
		background: #FCECD0;
		display: flex;
		align-items: center;
		padding: 0 32rpx;

		&__text {
			font-family: PingFang SC;
			font-weight: 500;
			font-size: 26rpx;
			color: #A65702;
			flex: 1;
			line-height: 36rpx;
		}

		&__icon {
			width: 38rpx;
			height: 39rpx;
			margin-right: 18rpx;
		}

		&__close {
			width: 19rpx;
			height: 19rpx;
		}
	}

	.head {
		margin-top: 10rpx;
		height: 82rpx;
		display: flex;
		align-items: center;
		padding: 0 37rpx 0 34rpx;
		border-bottom: 2rpx solid #F0EEEE;
		font-family: PingFang SC;
		font-weight: bold;
		font-size: 26rpx;
		color: #1E1E1E;

		&__title {
			width: 240rpx;
		}

		&__price {
			width: 170rpx;
			text-align: center;
		}

		&__kc {
			width: 170rpx;
			text-align: center;
		}

		&__cz {
			flex: 1;
			text-align: right;
		}
	}

	.list {
		padding: 0 35rpx 200rpx 12rpx;

		&__item {
			height: 82rpx;
			align-items: center;
			display: flex;
			border-bottom: 1rpx solid #E8E8E8;
			padding: 0 0 0 22rpx;

			&__title {
				display: flex;
				align-items: center;
				width: 240rpx;
				font-family: PingFang SC;
				font-weight: 500;
				font-size: 26rpx;
				color: #5A5A5A;
				line-height: 36rpx;

				&__pic {
					width: 60rpx;
					height: 60rpx;
					margin-right: 10rpx;

				}
			}

			&__price {
				font-family: PingFang SC;
				font-weight: 500;
				font-size: 26rpx;
				color: #5A5A5A;
				line-height: 36rpx;
				text-align: center;
				width: 170rpx;
			}

			&__cz {
				text-align: right;
				flex: 1;
				font-family: PingFang SC;
				font-weight: 500;
				font-size: 26rpx;
				color: #2A63F3;
				line-height: 36rpx;
			}
		}
	}

	.footer {
		width: 750rpx;
		background-color: #fff;
		height: 190rpx;
		position: fixed;
		bottom: 0;
		left: 0;
		display: flex;
		align-items: center;
		justify-content: center;

		&__btn {
			width: 304rpx;
			height: 87rpx;
			background: rgba(50, 98, 253, 0.16);
			border-radius: 5rpx;
			font-family: PingFang SC;
			font-weight: bold;
			font-size: 24rpx;
			color: #3262FD;
			display: flex;
			align-items: center;
			justify-content: center;
			margin: 0 12rpx;
		}

		.btn1 {
			background: #3262FD;
			color: #FFFFFF;
		}
	}

	.popbox {
		width: 476rpx;
		height: 341rpx;
		background: #ECECEC;
		border-radius: 30rpx;
		border: 0px solid #D4D4D4;

		&__text {
			font-family: PingFang SC;
			font-weight: bold;
			font-size: 24rpx;
			color: #000000;
			line-height: 33rpx;
			text-align: center;
			padding-top: 105rpx;
			margin-bottom: 76rpx;
		}
	}
	.dd {
		height: 100rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		border-bottom: 2rpx solid #F9F9F9;
	
		&__label {
			font-family: PingFang SC;
			font-weight: 500;
			font-size: 26rpx;
			color: #6D6D6D;
			line-height: 26rpx;
		}
	
		&__inp {
			font-family: PingFang SC;
			font-weight: 500;
			font-size: 26rpx;
			color: #333;
			line-height: 38rpx;
			text-align: right;
	
			.uni-input-placeholder {
				color: #6d6d6d !important;
			}
		}
	}
	.popbox1{
		padding: 30rpx 60rpx;
	}
</style>